package main.IO;

import java.io.*;

/**
 * @author ChengGM
 * @create 2017-01-12 15:28
 **/
public class FileTest {
    private static String path = "D:\\file";
    private static String fileNameTemp;

    public static void CreatFile(String fileName,String filecontent) {
        Boolean flag = false;
        fileNameTemp = path+fileName+".json";
        File file = new File(fileNameTemp);
        try {
            if(!file.exists()){
                file.createNewFile();
                flag = true;
                System.out.println("file success");
                createParentDirctory(fileNameTemp,filecontent);
            }
        } catch (Exception e) {
        }

    }

    public static void createParentDirctory(String filepath,String nstr) {
        Boolean flag = false;
        String filein = nstr +"\r\n";
        String temp = "";
        FileInputStream fis = null;
        InputStreamReader isr = null;
        BufferedReader br = null;
        FileOutputStream fos = null;
        PrintWriter pw = null;
        try {
            File file = new File(filepath);
            fis = new FileInputStream(file);
            isr = new InputStreamReader(fis);
            br = new BufferedReader(isr);
            StringBuffer buffer = new StringBuffer();
            for (int i = 0; (temp = br.readLine())!=null;i++) {
                buffer.append(temp);
                buffer = buffer.append(System.getProperty("line.separator"));
            }
            buffer.append(file);
            fos = new FileOutputStream(file);
        } catch (Exception e) {
        }


    }

}
//    public static void Serial(Long id, String content) {
//        try {
//            if(Files.exists(Paths.get(this.getTmpFile( id), new String[0]), new LinkOption[0])) {
//                Files.delete(Paths.get(this.getTmpFile(id), new String[0]));
//            }
//
//            Files.write(Paths.get(getTmpFile(id), new String[0]), content.getBytes(), new OpenOption[0]);
//        } catch (IOException var5) {
//            throw new RuntimeException("写入序列化文件失败");
//        }
//    }

